<?php
/**
 */
class MyFavoritesTable extends Doctrine_Table
{
	public function addToFavorite($memid,$type_id,$type)
	{
		
		$MyFavorites = new MyFavorites();
		$MyFavorites ->type = $type;
		$MyFavorites ->type_id = $type_id;
		$MyFavorites ->owner_id = $memid;
		$MyFavorites ->status = "Active";
		$MyFavorites ->added_date = date('Y-m-d H:i:s');
		//echo '<pre>';print_r($Expressions);exit;
		$MyFavorites ->save();
		return $MyFavorites->id;
	}
	public function inactiveFavorite($memid,$type_id,$type)
	{
		 $query = new Doctrine_Query();
		$query->delete('MyFavorites m')
			  ->where("m.type_id='".$type_id."'")
			  ->andWhere("m.owner_id='".$memid."'")
			  ->andWhere("m.type='".$type."'");
		  //echo $query;exit;
		return $query->execute();
	}
	public function getFavoritesByUserId($user_id,$currentPage,$resultsPerPage,$serValue='',$dateVallue)
	{
		 $query = new Doctrine_Query();
		$query->select('m.*')
		       ->from('MyFavorites m')
			  ->where("m.owner_id='".$user_id."'")
			  ->orderBy("m.id desc");
		  //echo $query;exit;
		if($dateVallue!='')
			   {
				//echo $dateVallue;exit;
					$query->andWhere("m.added_date LIKE '%".date('Y-m-d',strtotime($dateVallue))."%'");
			   }
			    //echo $query->getSql();exit;
				require_once('../database/models/dup_pager.php');
				$pager = new Pager($currentPage,$resultsPerPage);
				//echo $query->getSqlQuery();exit;
				$result = $pager->pagination($query);
				//echo '<pre>';print_r($result);exit;
				return $result;
	        
	
	}
}